<?php
namespace app\index\model;

use think\Model;

class CrmManage extends Model
{
    protected $insert = ['date'];

    protected function setDateAttr()
    {
        return time();
    }

    protected function setPasswordAttr($value)
    {
        return password($value);
    }

	/**
	 * 获取用户信息
	 * @param   $token          管理员凭证
	 * @param   $username       管理员用户名
     * @param   $id             管理员ID
     * @param   $field          字段
	 * @return  array
 	*/
    public function getManageInfo($token = '', $username = '', $id = '', $field = '*')
    {
        if (isset($token)) {
            if (!empty($token)) {
                $where['token'] = $token;
            }
        }
        if (isset($username)) {
            if (!empty($username)) {
                $where['username'] = $username;
            }
        }
        if (isset($id)) {
            if (!empty($id)) {
                $where['id'] = $id;
            }
        }
        $oneManage = db('crm_manage')->field($field)->where($where)->find();

        return $oneManage;
    }

    // 获取角色列表
    public function jueseList($type)
    {
        if (empty($type)) {
            apiReturn(201,'角色类型不能为空');
        }
        $jueseList = db('crm_manage')->field('username,name')->where(['type'=>$type,'status'=>1])->order('zu_id ASC')->select();
        return $jueseList;
    }

    public function item(){
        return $this->hasMany('CrmCustomer','banzhuren_manage_id','username')->field('client_id,banzhuren_manage_id,name,phone,formali_yingqi');
    }

}

?>